package com.lanlian.cayman.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.commonlib.data.ContractBean;
import com.lanlian.cayman.R;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 跟单选择合约Adapter
 *     version: 1.0
 * </pre>
 */
public class ChooseContractAdapter extends BaseQuickAdapter<ContractBean, BaseViewHolder> {

    private Map<String, Boolean> mMaps = new HashMap<>();
    private List<ContractBean> mlist;

    public ChooseContractAdapter(Context context, int layoutResId, List<ContractBean> list) {
        super(layoutResId, list);
        this.mContext = context;
        this.mlist = list;
        for (int i = 0; i < mlist.size(); i++) {

            mMaps.put(mlist.get(i).contractName, false);
        }
    }

    public void setChecked(String s) {
        for (int i = 0; i < mlist.size(); i++) {
            mMaps.put(mlist.get(i).contractName, false);
        }
        mMaps.put(s, true);
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, ContractBean item) {
        if (helper.getLayoutPosition() == 0) {
            helper.setText(R.id.tv_contract_name, "全部");
        } else {
            helper.setText(R.id.tv_contract_name, String.format("%s (%S)", item.contractName, item.contractNo));
        }
        helper.setChecked(R.id.cb_contract, mMaps.get(item.contractName));
    }

}
